export { };
// 封装存储类
class MyStorage {
	storage: Storage
	constructor(storage: Storage) {
		this.storage = storage
	}
	clear() {
		this.storage.clear();
	}
	removeItem(key: string) {
		this.storage.removeItem(key)
	}
	getItem(key: string) {
		try {
			return JSON.parse(this.storage.getItem(key) || '')
		} catch {
			return this.storage.getItem(key)
		}
	}
	setItem(key: string, value: any) {
		// 检测类型
		// typeof 返回值
		/**
		 * number
		 * boolean
		 * undefined
		 * function 
		 * object
		 * string
		 * Symbol
		 * bigint
		 * */
		switch (typeof value) {
			case "string":
				this.storage.setItem(key, value);
				break;
			case "bigint":
			case "number":
			case "boolean":
			case "symbol":
			case "function":
				this.storage.setItem(key, value.toString());
				break;
			case "object":
				this.storage.setItem(key, JSON.stringify(value));
				break;
			case "undefined":
				break;

		}
		// if (typeof value === 'string') {
		// 	this.storage.setItem(key, value)
		// }
		// else if(typeof value === 'bigint' || typeof value ==='number') {

		// }
	}
}


// const arr = [{ name: '张三', age: 19 }, { name: '李四', age: 20 }]

// localStorage.setItem('arr', JSON.stringify(arr))
// const s = localStorage.getItem('arr') || ''
// const result = JSON.parse(s)
// console.log(result)




